package router

import (
	"cloud-entropy-storage-system/server/internal/logic/api"
	"cloud-entropy-storage-system/server/internal/middleware"
)

func setApi(s *Server) {
	r := s.Engine
	r.Use(middleware.Cors())

	apiRouter := r.Group("/api")

	adminLogic := api.NewAdminLogic(s.Log, s.db, s.gc)
	{
		apiRouter.POST("/login", adminLogic.Login())
		apiRouter.POST("/password", adminLogic.Password())
	}

	fileLogic := api.NewFileLogic(s.Log, s.meta, s.manager, s.cfg)
	{
		apiRouter.POST("/upload/*path", fileLogic.Upload())
		apiRouter.GET("/file/*path", fileLogic.GetFile())
		apiRouter.GET("/delete/*path", fileLogic.DeleteFile())
		apiRouter.GET("/list", fileLogic.List())
	}

	apiV2 := apiRouter.Group("/v2")
	{
		apiV2.POST("/upload/*path", fileLogic.UploadV2())
	}

	dirLogic := api.NewDirLogic(s.Log, s.cfg, s.db)
	dirRouter := apiRouter.Group("/dir")
	{
		dirRouter.GET("/list", dirLogic.List())
		dirRouter.POST("/set", dirLogic.Set())
		dirRouter.POST("/delete", dirLogic.Delete())
	}
}
